﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GtsServer.Common;

namespace GtsServer.DAL
{
    public partial class OrderDetailDAL
    {
        public OrderDetailDAL() { }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int pageIndex, int pageSize, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from ( select od.OrderID,oer.OrderAccount,t.Name TaskName,pt.Name,ur.IMSI,oer.Price,case oer.State when 1 then '已支付' else '未支付' end StateName,oer.CreateTime,oer.PayTime,ROW_NUMBER() OVER(Order by oer.CreateTime desc) as RowNumber ");
            strSql.Append(" from OrderDetail od left join Prize pz on od.PrizeID=pz.ID left join Task t on t.ID =od.TaskID left join PrizeType pt on pz.PrizeTypeID=pt.ID left join [Order] oer on od.OrderID=oer.ID left join [User] ur on oer.UserID=ur.ID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(") a where  RowNumber BETWEEN " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize + ";");
            strSql.Append(" select COUNT(1) from OrderDetail od left join Prize pz on od.PrizeID=pz.ID left join PrizeType pt on pz.PrizeTypeID=pt.ID left join [Order] oer on od.OrderID=oer.ID left join [User] ur on oer.UserID=ur.ID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
